package work.xiaohong.jijin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import work.xiaohong.jijin.entity.*;
import work.xiaohong.jijin.entity.lianghua.LiangHuaPoint;
import work.xiaohong.jijin.service.IFreeService;
import work.xiaohong.jijin.service.IStoreService;
import work.xiaohong.jijin.util.JijinHttpUtil;
import work.xiaohong.jijin.util.JijinUrlUtil;
import work.xiaohong.model.Result;
import work.xiaohong.model.StatusCode;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *  前端控制器
 * @author xiaohong
 * @since 2021-11-07 13:37:13
 */
@Tag(name = "基金仓库接口文档")
@RestController
@RequestMapping("/store")
public class StoreController {

    @Autowired
    private IStoreService storeService;

    @Autowired
    private IFreeService freeService;

    private static Set<String> mySet = new HashSet<String>();


    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 8, 10, TimeUnit.MINUTES,
                new LinkedBlockingQueue<>(200), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        for (int i = 0; i < 200; i++) {
            threadPoolExecutor.execute(new Runnable() {
                @SneakyThrows
                @Override
                public void run() {
                    System.out.println(Thread.currentThread()+"-----开始执行");
                    // 休眠0.1s后再去查
                    Thread.sleep(5000);
                    System.out.println(Thread.currentThread()+"-----执行完成");
                }
            });
        }

    }

    // 获得当前时间多少天后的日期
    public static String getDay(Integer days){
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date result = (Date) calendar.getTime();
        return format.format(result);
    }

    /***
     * 条件分页查询
     * @param store
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "条件分页查询",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@RequestBody(required = false) @Parameter(name = "Store对象",required = true) Store store, @PathVariable(value="page")  int page, @PathVariable(value="size")  int size){
        Page<Store> pageInfo = storeService.page(new Page<Store>(page,size),new QueryWrapper<Store>(store));
        return new Result<Page>(true,StatusCode.OK.getCode(),"查询成功",pageInfo);
    }


    /***
     * 分页查询
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @Operation(summary = "分页查询",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@PathVariable(value="page")  int page, @PathVariable(value="size")  int size){
        //调用StoreService实现分页查询Store
        Page<Store> pageInfo = storeService.page(new Page<>(page,size));
        return new Result<Page>(true,StatusCode.OK.getCode(),"查询成功",pageInfo);
    }

    /***
     * 条件查询
     * @param store
     * @return
     */
    @Operation(summary = "条件查询",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping(value = "/search" )
    public Result<List<Store>> findList(@RequestBody(required = false) @Parameter(name = "Store对象",required = true) Store store){
        List<Store> list = storeService.list(new QueryWrapper<Store>(store));
        return new Result<List<Store>>(true,StatusCode.OK.getCode(),"查询成功",list);
    }


    /***
     * 根据Id删除store数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID删除Store",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "删除对象ID", required = true)
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable(value="id") Integer id){
        storeService.removeById(id);
        return new Result(true,StatusCode.OK.getCode(),"删除成功");
    }



    /***
     * 根据Id批量删除store数据
     * @param ids
     * @return
     */
    @Operation(summary = "根据Id批量删除Store",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @DeleteMapping
    public Result deleteByIds(@RequestBody @Parameter(name = "需要删除的Store对象id集合",required = true) List<Integer> ids){
        storeService.removeByIds(ids);
        return new Result(true,StatusCode.OK.getCode(),"删除成功");
    }

    /***
     * 根据ID修改Store数据
     * @param store
     * @return
     */
    @Operation(summary = "根据ID修改Store",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PutMapping
    public Result updateById(@RequestBody @Parameter(name = "Store对象",required = true) Store store){
        storeService.updateById(store);
        return new Result(true,StatusCode.OK.getCode(),"修改成功");
    }


    /***
     * 卖出基金
     * @param id
     * @return
     */
    @Operation(summary = "卖出基金",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @Transactional
    @PutMapping(value = "/sell/{id}" )
    public Result sell(@PathVariable Integer id){
        try {
            Store store = new Store();
            // 补充id
            store.setId(id);
            // 补充参数
            store.setStatus(3);
            //调用storeService实现修改Store
            storeService.updateById(store);
            // 可赎份额更新
            Free seletFree = new Free();
            seletFree.setCode(storeService.getById(id).getCode());
            Free one = freeService.getOne(new QueryWrapper<Free>(seletFree));
            if (one != null){
                Free ufree = new Free();
                Float buyNumber = storeService.getById(id).getBuyNumber();
                ufree.setFreeNumber(one.getFreeNumber()-buyNumber);
                ufree.setId(one.getId());
                freeService.updateById(ufree);
                return new Result(true,StatusCode.OK.getCode(),"卖出成功");
            }else {
                return new Result(true,StatusCode.ERROR.getCode(),"没有该基金可赎记录");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR.getCode(),"卖出失败");
        }

    }


    /***
     * 撤回卖出
     * @param id
     * @return
     */
    @Operation(summary = "撤回卖出",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @Transactional
    @PutMapping(value = "/recall/{id}" )
    public Result recall(@PathVariable Integer id){
        try {
            Store store = new Store();
            // 补充id
            store.setId(id);
            // 补充参数
            store.setStatus(1);
            //调用storeService实现修改Jijin
            storeService.updateById(store);
            // 可赎份额更新
            Free seletFree = new Free();
            seletFree.setCode(storeService.getById(id).getCode());
            Free one = freeService.getOne(new QueryWrapper<>(seletFree));
            if (one != null){
                Free ufree = new Free();
                Float buyNumber = storeService.getById(id).getBuyNumber();
                ufree.setFreeNumber(one.getFreeNumber()+buyNumber);
                ufree.setId(one.getId());
                freeService.updateById(ufree);
                return new Result(true,StatusCode.OK.getCode(),"撤回卖出成功");
            }else {
                return new Result(true,StatusCode.ERROR.getCode(),"没有该基金可赎记录");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR.getCode(),"撤回卖出失败");
        }

    }


    /***
     * 新增Store数据
     * @param store
     * @return
     */
    @Operation(summary = "添加Store",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping
    public Result add(@RequestBody  @Parameter(name = "Store对象",required = true) Store store){
        try {
            // 格式化数据
            // 保留两位小数
//            DecimalFormat df = new DecimalFormat("0.00");
            store.setBuyMoney(store.getBuyMoney());
            storeService.save(store);
            return new Result(true,StatusCode.OK.getCode(),"添加成功");
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR.getCode(),"添加失败",e);
        }

    }

    /***
     * 根据ID查询Store数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID查询Store",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "查询对象ID", required = true)
    @GetMapping("/{id}")
    public Result<Store> findById(@PathVariable(value="id") Integer id){
        Store store = storeService.getById(id);
        return new Result<Store>(true,StatusCode.OK.getCode(),"查询成功",store);
    }

    /***
     * 根据Id批量查询Store数据
     * @param ids
     * @return
     */
    @Operation(summary = "根据Id批量查询Store数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping("/ids")
    public Result<List<Store>> findByIds(@RequestBody @Parameter(name = "需要查询的Store对象id集合",required = true) List<Integer> ids){
        List<Store> storeList = storeService.listByIds(ids);
        return new Result<List<Store>>(true,StatusCode.OK.getCode(),"查询成功",storeList);
    }

    /***
     * 根据code查询某基金最新情况
     * @param code
     * @return
     */
    @Operation(summary = "根据code查询某基金最新情况",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "code", description = "code", required = true)
    @GetMapping("/newest/{code}")
    public Result<StoreDetail> getNewest(@PathVariable String code) {
        HttpResult httpResult = null;
        try {
            String url = JijinUrlUtil.creatUrl(code, 13);
            httpResult = JijinHttpUtil.sendGetReq(url);
            StoreDetail storeDetail = new StoreDetail();
            storeDetail.setGuzhi(httpResult.getGsz()); // 最新估值
            storeDetail.setPercent(httpResult.getGszzl()); // 最新涨跌幅

            // 获取可赎份额
            Free free = new Free();
            free.setCode(code);
            Free one = freeService.getOne(new QueryWrapper<>(free));
            if (one == null){
                storeDetail.setFreeNumberSum(0F);
            }else {
                storeDetail.setFreeNumberSum(one.getFreeNumber());
            }
            return new Result<StoreDetail>(true, StatusCode.OK.getCode(), "查询最新估值成功", storeDetail);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result<StoreDetail>(true, StatusCode.ERROR.getCode(), "查询最新估值失败");
        }

    }


    /***
     * 根据code查询基金名称
     * @param code
     * @return
     */
    @Operation(summary = "根据code查询基金名称",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "code", description = "code", required = true)
    @GetMapping("/name/{code}")
    public Result<String> findName(@PathVariable String code) {
        HttpResult httpResult = null;
        try {
            String url = JijinUrlUtil.creatUrl(code, 13);
            httpResult = JijinHttpUtil.sendGetReq(url);
            return new Result<String>(true, StatusCode.OK.getCode(), "查询基金名称成功", httpResult.getName());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result<String>(true, StatusCode.ERROR.getCode(), "查询基金名称失败");
        }

    }



    /***
     * 根据code查询Jijin数据及建议数据
     * @param code
     * @param model  建议模式（zy： 止盈  zs： 止损）
     * @return
     */
    @Operation(summary = "根据code查询Jijin数据及建议数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH,name = "code", description = "code", required = true),
            @Parameter(in = ParameterIn.PATH,name = "model", description = "model", required = true)
    })
    @GetMapping("/{code}/{model}")
    public Result<List<Store>> findByCodeAndModel(@PathVariable(value = "code") String code, @PathVariable(value = "model") String model) throws Exception {
        List<Store> list =  new ArrayList<>();
        try {
            if (code == null || model == null){
                return new Result(true, StatusCode.UNPOWER.getCode(), "参数错误");
            }else {
                // 根据code查询已买入的基金
                Store store1 = new Store();
                store1.setCode(code);
                store1.setStatus(1);
                list = storeService.list(new QueryWrapper<>(store1)); // 已买入基金列表
                Float freeNumber =findFreeNumber(code).getData();  // 可赎回份额
                if (list != null && list.size() != 0){
                    String url = JijinUrlUtil.creatUrl(code, 13);
                    HttpResult httpResult = JijinHttpUtil.sendGetReq(url);
                    Float nav = httpResult.getGsz();  //获取当前净值
                    if ("zy".equalsIgnoreCase(model)){
                        // 止盈模式
                        for (Store store : list) {
                            if (nav > store.getBuyPrice() * 1.05  && freeNumber >= store.getBuyNumber()){
                                store.setIsIdea(1);
                            }else {
                                store.setIsIdea(0);
                            }
                            store.setProfit((nav-store.getBuyPrice())*store.getBuyNumber());
                        }
                        return new Result<List<Store>>(true, StatusCode.OK.getCode(), "止盈模式", list);
                    }else if("zs".equalsIgnoreCase(model)){
                        // 止损模式

                        Float profitMoney = 0F; // 盈利总额

                        List<Float> positive = new ArrayList<>(); // 盈利列表
                        List<Float> negative = new ArrayList<>(); // 亏损列表

                        // 将数据分类
                        for (Store store : list) {
                            store.setIsIdea(0);
                            if (store.getBuyPrice() <= nav){
                                positive.add(store.getBuyPrice());
                            }else {
                                negative.add(store.getBuyPrice());
                            }
                        }

                        boolean positive_flag = true; // 盈利资金是否全部走完标志

                        a:while (positive.size() > 0){
                            // 寻找盈利最大的基金
                            Float positive_number = Float.MAX_VALUE;
                            for (Float aFloat : positive) {
                                if (aFloat <= positive_number){}
                                positive_number = aFloat;
                            }

                            // 找到最大盈利基金数据
                            b:for (Store store : list) {
                                if (store.getBuyPrice() == positive_number){
                                    // 找到后先看可赎回资金够不够
                                    if (freeNumber >= store.getBuyNumber()){
                                        freeNumber -= store.getBuyNumber();
                                        Float positive_profit = store.getBuyNumber() * ( nav - store.getBuyPrice()); // 盈利金额
                                        profitMoney += positive_profit;
                                        store.setIsIdea(1);
                                        // 剔除positive数据
                                        positive.remove(positive_number);
                                        continue a;
                                    }else {
                                        // 可赎回资金不够了 直接退出外层循环
                                        positive_flag = false;
                                        break a;
                                    }
                                }
                            }
                        }

                        // 判断盈利资金是否走完
                        if (positive_flag){
                            // 走完了
                            c:while (negative.size() > 0){
                                // 寻找亏损最大的基金
                                Float negative_number = 0F;
                                for (Float aFloat : negative) {
                                    if (aFloat >= negative_number){
                                        negative_number = aFloat;
                                    }
                                }

                                // 找到最大亏损基金数据
                                d:for (Store store : list) {
                                    if (store.getBuyPrice() == negative_number) {
                                        // 找到后先看可赎回资金够不够且盈利额是否够
                                        Float negative_profit = store.getBuyNumber() * (store.getBuyPrice() - nav); // 亏损金额
                                        if (freeNumber >= store.getBuyNumber()&& profitMoney >= negative_profit) {
                                            freeNumber -= store.getBuyNumber();
                                            profitMoney -= negative_profit;
                                            store.setIsIdea(1);
                                            // 剔除positive数据
                                            positive.remove(negative_number);
                                            continue c;
                                        } else {
                                            // 可赎回资金不够了或盈利抵消没了 直接退出外层循环
                                            break c;
                                        }
                                    }
                                }
                            }
                        }

                        // 没走完 直接返回数据
                        return new Result<List<Store>>(true, StatusCode.OK.getCode(), "止损模式",list);
                    }
                }else {
                    return new Result(true, StatusCode.ERROR.getCode(), "你已空仓");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return new Result(true, StatusCode.ERROR.getCode(), "服务器错误或参数错误");
        }

        return new Result<List<Store>>(true, StatusCode.OK.getCode(), "止损模式",list);
    }


    /***
     * 根据策略查询Jijin列表数据
     * @return
     */
    @Operation(summary = "根据策略查询Jijin列表数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/list/{model}")
    public Result<Object> findListByModel(@PathVariable String model){
        try {
            HashMap<String, StoreList> mapList = new HashMap<>();
            HashMap<String, List<Store>> map = new HashMap<>();

            // 获取所有已确认并持有数据
            Store store = new Store();
            store.setStatus(1);
            List<Store> list = storeService.list(new QueryWrapper<>(store));

            // 更新mySet 获取所有持有数据
            mySet = new HashSet<>();
            for (Store jj : list) {
                mySet.add(jj.getCode());
            }

            // 初始化map
            for (String ms : mySet) {
                map.put(ms, new ArrayList<Store>());
            }

            // 添加map数据
            for (Store jj : list) {
                map.get(jj.getCode()).add(jj);
            }

            // 填充mapList
            for (String s : map.keySet()) {
                StoreList storeList = new StoreList();
                String code = map.get(s).get(0).getCode();
                String name = map.get(s).get(0).getName();
                Float sumMoney = 0F; // 所有金额
                Free free = new Free();
                free.setCode(code);
                List<Free> freeList = freeService.list(new QueryWrapper<>(free));
                Float freeNumber = findFreeNumber(code).getData();

                Float allNumber = 0F; // 所有份额

                for (Store jj : map.get(s)) {
                    sumMoney += jj.getBuyMoney();
                    allNumber += jj.getBuyNumber();
                }
//                DecimalFormat df = new DecimalFormat("0.00");
                // 格式化数据 保留两位小数
                storeList.setCode(code);
//                jijinList.setAllNumber(Float.parseFloat(df.format(allNumber)));
                storeList.setAllNumber(allNumber);
//                jijinList.setFreeNumber(Float.parseFloat(df.format(freeNumber)));
                storeList.setFreeNumber(freeNumber);
                storeList.setName(name);
//                jijinList.setSumMoney(Float.parseFloat(df.format(sumMoney)));
                storeList.setSumMoney(sumMoney);

                // 计算建议操作总额
                Float ideasNumber = 0F;

                List<Store> ideas = (List<Store>)findByCodeAndModel(code, model).getData();

                for (Store idea : ideas) {
                    if (idea.getIsIdea() == 1){
                        ideasNumber += idea.getBuyNumber();
                    }
                }

                storeList.setIdeasNumber(ideasNumber);

                mapList.put(name,storeList);
            }

            return new Result<Object>(true, StatusCode.OK.getCode(),"查询成功",mapList) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Object>(true, StatusCode.ERROR.getCode(),"查询失败") ;
        }
    }

    /***
     * 查询可赎份额
     * @return
     */
    @Operation(summary = "查询可赎份额",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/freeNumber/{code}")
    public Result<Float> findFreeNumber(@PathVariable String code){
        try {
            Float freeNumber = null;  // 可赎回份额
            Free free = new Free();
            free.setCode(code);
            List<Free> freeServiceList = freeService.list(new QueryWrapper<>(free));
            if (freeServiceList == null || freeServiceList.size() == 0){
                // 没有该可赎份额记录
                free.setName(findName(code).getData());
                free.setFreeNumber(0F);
                freeService.save(free);
                freeNumber = 0F;
            }else  {
                freeNumber = freeServiceList.get(0).getFreeNumber();
            }
            return new Result<Float>(true, StatusCode.OK.getCode(),"查询可赎份额成功",freeNumber) ;
        }catch (Exception e){
            return new Result<Float>(true, StatusCode.ERROR.getCode(),"查询可赎份额失败") ;
        }
    }


    /***
     * 查询执行中的数据
     * @return
     */
    @Operation(summary = "查询执行中的数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/doing")
    public Result<List<Store>> findIsDoing(){
        try {
            List<Store> list = storeService.findIsDoing();
            return new Result<List<Store>>(true, StatusCode.OK.getCode(),"查询成功",list) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<List<Store>>(true, StatusCode.ERROR.getCode(),"查询失败") ;
        }
    }

    /***
     * 分页查询执行完的数据
     * @return
     */
    @Operation(summary = "分页查询执行完的数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/finish/{page}/{size}")
    public Result<Page> findFinish(@PathVariable(value="page")  int page, @PathVariable(value="size")  int size){
        try {
            Page pageResult = storeService.findIsOver(page,size);
            return new Result<Page>(true, StatusCode.OK.getCode(),"查询成功",pageResult) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Page>(true, StatusCode.ERROR.getCode(),"查询失败") ;
        }
    }


    /***
     * 查询Jijin全部数据
     * @return
     */
    @Operation(summary = "查询Jijin全部数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/all")
    public Result<Object> findAll(){
        try {
            HashMap<String, List<Store>> map = new HashMap<>();

            // 获取所有已确认并持有数据
            Store store = new Store();
            store.setStatus(1);
            List<Store> list = storeService.list(new QueryWrapper<>(store));

            // 更新mySet 获取所有持有数据
            mySet = new HashSet<>();
            for (Store jj : list) {
                // 格式化数据
                mySet.add(jj.getCode());
            }

            // 初始化map
            for (String ms : mySet) {
                map.put(ms, new ArrayList<Store>());
            }

            // 添加map数据
            for (Store jj : list) {
                map.get(jj.getCode()).add(jj);
            }

            return new Result<Object>(true, StatusCode.OK.getCode(),"查询成功",map) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Object>(true, StatusCode.ERROR.getCode(),"查询失败") ;
        }

    }



    /***
     * 查询Jijin菜单
     * @return
     */
    @Operation(summary = "查询Jijin菜单",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/menu")
    public Result<List> findMenu(){
        try {

            // 获取所有已确认并持有数据
            Store store = new Store();
            store.setStatus(1);
            List<Store> list = storeService.list(new QueryWrapper<>(store));

            // 获取所有持有并去重
            Set<Map<String, String>> resultSet = new HashSet<>();
            for (Store jj : list) {
                Map<String, String> map = new HashMap<>();
                map.put(jj.getCode(),jj.getName());
                resultSet.add(map);
            }

            List resultList = new ArrayList();
            for (Map<String, String> mp : resultSet) {
                for (String s : mp.keySet()) {
                    StoreMenu storeMenu = new StoreMenu();
                    storeMenu.setCode(s);
                    storeMenu.setName(mp.get(s));
                    resultList.add(storeMenu);
                }
            }

            return new Result<List>(true, StatusCode.OK.getCode(),"查询成功",resultList) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<List>(true, StatusCode.ERROR.getCode(),"查询失败") ;
        }
    }


    /**
     * list反转
     * @param list
     * @return
     */
    public List<Store> Listreverse(List<Store> list) {
        List<Store> resultList =  new ArrayList<Store>();

        while (list.size() > 0){
            resultList.add(list.get(list.size()-1));
            list.remove(list.get(list.size()-1));
        }

        return resultList;
    }


//    /**
//     * 根据list创建修改时间字符串
//     * @param list
//     * @return
//     */
//    public List<Store> listAddTimeStr(List<Store> list) {
//
//        // 格式化数据
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        for (int i = 0; i < list.size(); i++) {
//            Store store = list.get(i);
//            store.setGmtCreateStr(format.format(store.getGmtCreate()));
//            store.setGmtModifiedStr(format.format(store.getGmtModified()));
//        }
//
//        return list;
//    }


}
